package cn.tansanqinger.controller.knowledge;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.tansanqinger.pojo.Catalogue;
import cn.tansanqinger.service.knowledge.IKnowledgeMenuService;
import cn.tansanqinger.service.knowledge.IKnowledgeService;
import cn.tansanqinger.util.Tools;

@Controller
@RequestMapping("/admin/knowledge")
public class KnowledgeUpdataController {
	
	@Autowired
	private IKnowledgeService service;
	@Autowired
	private IKnowledgeMenuService mservice;
	
	@RequestMapping("/list")
	public ModelAndView list(ModelAndView mv) {
		mv.setViewName("knowledge/list");
		mv.addObject("firstMenu", mservice.selectMenu(0));
		return mv;
	}
	
	@RequestMapping("/addKnowledge")
	@ResponseBody
	public Map<String , Object> addKnowledge(HttpServletRequest request) {
		return service.add(request);
	}
	
	@RequestMapping("/nextMenu")
	@ResponseBody
	public List<Catalogue> nextMenu(HttpServletRequest request){
		return mservice.selectMenu(Integer.parseInt(Tools.isEmpty(request.getParameter("ctop"))));
	}
	
}
